
		class Detail{
			constructor(options){
				this.imgbox1 = options.imgbox1;
				this.imgbox2 = options.imgbox2;
				this.list = options.list;
				this.url = options.url;
				
				this.getCookie()
				this.addEvent()
			}
			
			load(){
				var that = this
				$.ajax({
					url:this.url,
					// dataName:this.dataName,
					// id:this._id,
					type:'get',
					data:{
						dataName:this.dataName,
						_id:this._id
					},
					success:function(res){
						// console.log(res);
						// console.log(that.dataName);

						that.res = res;
						that.display();
//						that.display()
						// that.getCookie()
					}
					
				});
				
				
			}
			
			getCookie(){
				this._id = JSON.parse($.cookie("goodsdetail")).index;
				this.dataName = JSON.parse($.cookie("goodsdetail")).dataName; 
				// console.log(JSON.parse($.cookie("goodsdetail")),this._id,this.dataName)
				// console.log($.cookie("goodsdetail"))
				
				this.load()
			}
			
			display(){
				// console.log(this.res)
				// console.log(this.res.length)
				var str = ""
				// var pic = ""
				// for(var i = 0;i<this.res.length;i++){
				// 	for(var j = 0;j<this.res[i].length;j++){
				// 		if(this.goodsdetail==this.res[i][j].id){
					str +=`
					<div index="${this.res.page_data._id}">
					<p class="goodsinfo" >${this.res.page_data.title}</p>
					<span class="price">¥${this.res.page_data.des}</span>
					<div>数量:<input type="number" name="num" id="num" min= 1 value= "1"/>
					</div>
					<input type="button" name="mai" id="mai" value="加入购物车" />
					</div>
					`
				var pic = `${this.res.page_data.detail.auth_icon}`
				// 		}
				// 	}
					
				// }
				this.list.html(str)
				this.imgbox1.attr("src",pic)
				// this.imgbox2.attr("src",pic)
			}
			
			addEvent(){
				var that = this
				this.list.on("click","#mai",function(){
					that.id = $(this).parent().attr("index")
					// console.log(that.id)
					that.num = parseInt($(this).parent().children("div").children("#num").val())
					
					that.setGoods()
				})
			}
			
			setGoods(){
				// var that = this;
				// $.ajax({
				// 	url:'api/user',
				// 	type:'get',
				// 	success:function(res1){
				// 		that.id1 = res1.data._id
				// 		console.log(that.id1)
				// 		console.log(typeof parseInt(that.num))
				// 		console.log(that.res.page_data._id)
				// 		console.log(that.dataName)
				// 		$.ajax({
				// 			url:"api/addcar",
				// 			type:'post',
				// 			data:{
				// 				_id:that.id1,
				// 				num:that.num,
				// 				goodsid:that.res.page_data._id,
				// 				goodsdn:that.dataName
				// 			},
				// 			success:function(res2){
				// 				console.log(res2)
				// 			}
				// 		})
				// 	}
				// })

				if($.cookie("goods") == null){
					this.goods = []
				}else{
					this.goods = JSON.parse($.cookie("goods"))
				}
				console.log(this.goods)
				if(this.goods.length<1){
					this.goods.push({
						_id:this._id,
						num:this.num,
						dataName:this.dataName
					})
				}else{
					var onoff = true;
					for(var i=0;i<this.goods.length;i++){
						if(this.goods[i]._id == this._id){
							this.goods[i].num += this.num;
							onoff = false;
							break;
						}
					}
					if(onoff){
						this.goods.push({
						_id:this._id,
						num:this.num,
						dataName:this.dataName
						})
					}
				}
				$.cookie("goods",JSON.stringify(this.goods))
			}
				

				}
				// $.cookie("goods",JSON.stringify(this.goods))
			// }
			
			


		new Detail({
			imgbox1:$(".img1"),
			imgbox2:$(".img2"),
			list:$(".detail"),
			url:"api/detail"
		})
